package zxing.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

import org.litepal.crud.DataSupport;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Hashtable;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.virtualapp.R;
import io.virtualapp.abs.ui.VActivity;
import io.virtualapp.bean.MakeBean;
import io.virtualapp.bean.NumBean;
import io.virtualapp.bean.Userbean;

/**
 * Created by Administrator on 2017/3/28.
 * <p>
 * 生成名片
 */

public class BusinessCardActivity extends VActivity {
    private EditText et_only_company;
    private EditText et_only_position;
    private EditText et_only_phone;
    private EditText et_only_email;
    private EditText et_only_web1;
    private EditText et_only_add;
    private EditText et_only_note;
    private EditText et_only_name;
    @BindView(R.id.head_back)
    ImageView head_back;
    @BindView(R.id.head_center_title)
    TextView head_center_title;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_generate);
        ButterKnife.bind(this);
        et_only_company = (EditText) findViewById(R.id.et_only_company);
        et_only_position = (EditText) findViewById(R.id.et_only_position);
        et_only_phone = (EditText) findViewById(R.id.et_only_phone);
        et_only_email = (EditText) findViewById(R.id.et_only_email);
        et_only_web1 = (EditText) findViewById(R.id.et_only_web1);
        et_only_add = (EditText) findViewById(R.id.et_only_add);
        et_only_note = (EditText) findViewById(R.id.et_only_note);
        et_only_name = (EditText) findViewById(R.id.et_only_name);

        initView();
    }

    private void initView() {
        head_center_title.setText("名片二维码");
        head_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.but).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (TextUtils.isEmpty(et_only_name.getText().toString())) {
                    Toast.makeText(BusinessCardActivity.this, "姓名不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }
                String name = et_only_name.getText().toString().trim();
                String company = et_only_company.getText().toString().trim();
                String position = et_only_position.getText().toString().trim();
                String phone = et_only_phone.getText().toString().trim();
                String email = et_only_email.getText().toString().trim();
                String web1 = et_only_web1.getText().toString().trim();
                String add = et_only_add.getText().toString().trim();
                String note = et_only_note.getText().toString().trim();
                String contents = "BEGIN:VCARD\nVERSION:3.0\n" + "FN:" + name
                        + "\nORG:" + company + "\nTITLE:" + position
                        + "\nNOTE:" + note + "\nTEL:" + phone + "\nADR:" + add
                        + "\nEMAIL:" + email + "\nEND:VCARD";
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
                Date date = new Date(System.currentTimeMillis());
                String n = simpleDateFormat.format(date);
                MakeBean user = new MakeBean();
                user.setName(n);
                user.setTit(contents);
                user.save();
                NumBean numBean = new NumBean();
                if (DataSupport.findFirst(NumBean.class) != null) {
                    DataSupport.deleteAll(NumBean.class);
                }
                numBean.setNum(2);
                numBean.save();
                Intent intent = new Intent(getActivity(), CodeDisplayActivity.class);
                intent.putExtra("data", contents);
                intent.putExtra("title", "名片二维码");
                startActivity(intent);

            }
        });
    }


}
